package prictise.com.application1.suanFa;

public class CountSort {
  
  int[] arr = {5, 3, 7, 6, 4, 1, 0, 2, 9, 10, 8};
  
  public static void count(int[] arr) {
    int size = arr.length;
    int min = 0;
    int max = 0;
    for (int i = 0; i < size; i++) {
      if (arr[i] < min) {
        min = arr[i];
      }
      if (arr[i] > max) {
        max = arr[i];
      }
    }
    
    int newSize = max - min + 1;
    int[] newArr = new int[newSize];
    for (int i = 0; i < newSize; i++) {
      newArr[arr[i] - min]++;
    }
    int j = 0;
    int[] resultArr = new int[size];
    for (int i = 0; i < newSize; i++) {
      while (newArr[i] > 0) {
        resultArr[j] = i + min;
        newArr[i]--;
        j++;
      }
    }
    
  }
  
  public static void main(String[] args) {
  
  }
}
